<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title>美业红</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <link href="/public/css/main.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script type="text/javascript" src='/public/js/main/main.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body style="background-color: #f4f4f4;">
        <div class="navigation">
            <div class='navlogo'>
            <a href='/'><img class='_navlogo' src="/public/images/logo.png"></a>
            </div>
            <div class='navson'>
                <ul class='fr'>
                <li><a href='/' class='anchor'><b>主页</b></a></li>
                <li><a href="/home/store" class='anchor'><b>店铺</b></a></li>
                <li><a href="/home/barber" class='anchor'><b>成员</b></a></li>
                <li><a href="/home/action" class='anchor'><b>活动</b></a></li>
                <li><a href="/home/order" class='anchor'><b>订单</b></a></li>
                <li><a href="/home/coupon" class='anchor'><b>优惠券</b></a></li>
                <li><a href="/home/goods" class='anchor'><b>商品</b></a></li>
                </ul>
           </div>
            <?php if($_SESSION['id']>0){?>
            <div style="float:right;padding-right:10%">你好:<span id='login_name'></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/repassword'>修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/logout'>退出</a></div>
            <?php }?>
        </div>
        <div style='margin-top:80px;width:100%'>
            <img class='_navlogo' src="/public/images/contentlogo.png" style='width:100%;height:100px'>
        </div>
        <div class='container'>
            <div class='_main'>
            <div class='_line'></div> 
<div class="_contro">
    <select id="store" name="store">
        <option value="0">全部店铺</option>
        <?php foreach($_store as $v){?>
        <option value='<?php echo $v['id'];?>' <?php if($store_id==$v['id']){echo "selected='selected'";}?>><?php echo $v['name'];?></option>
        <?php }?>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="type" id="type">
        <option <?php if($type == 0 ){echo 'selected="selected"';}?> value="0">全部优惠券</option>
        <option <?php if($type == 1){echo 'selected="selected"';}?> value="1">折扣劵</option>
        <option <?php if($type == 2){echo 'selected="selected"';}?> value="2">现金劵</option>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    <select name="status" id="status">
        <option <?php if($status == 0 ){echo 'selected="selected"';}?> value="0">全部状态</option>
        <option <?php if($status == 1){echo 'selected="selected"';}?> value="1">已发布</option>
        <option <?php if($status == 2){echo 'selected="selected"';}?> value="2">草稿</option>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="/home/coupon/create" class="_a"><font class="_font"><b>+</b>创建优惠劵</font></a>
</div>
<div class='_cut'></div>
<div id='content'>
<?php foreach($coupon as $k=>$v){ ?>
<?php if($k%3==0){ ?>
<div class='row'>
    <?php }?>
    <div class='col-sm-3 col-md-4 full'>
        <div class='thumbnail' style="margin-bottom:10px">
            <div style="height:12rem;overflow: hidden">
                <a target="_blank" href='/home/coupon/info?coupon_id=<?php echo ($v["id"]); ?>'><img class='_img' src='<?php echo ($v["style"]); ?>' style='width:100%;height:100%'/></a>
            </div>
        </div>
        <div class='caption' style='overflow: hidden'>
            <div>
                <a target="_blank" href='/home/coupon/info?coupon_id=<?php echo ($v["id"]); ?>'><span style='margin-left:1rem'> <?php echo $v['name']; ?> </span></a>
                &nbsp;&nbsp;&nbsp;
                <span>创建时间：<?php echo date("Y-m-d",$v['create_time']); ?></span>
            </div>
            <span style="margin-left: 6px"><?php echo $v['status']; ?></span>
                <span style="margin-left: 6px">已领取：<?php echo $v['count'];?>张</span>
                <span style="margin-left: 6px">剩余：<?php if($v['num'] == -1){ echo '不限 ';}else{echo ($v['num']-$v['count']);}?> 张</span>
        </div>
        <div style='float:right;margin-right:2rem;'>
            <?php if($v['end_date']>time() && $v['status']=='发放中' ){ ?>
            <input type='hidden'  id='coupon_name_<?php echo ($v["id"]); ?>' value='<?php echo $v['name']; ?>' >
            <input type='hidden' name='' id='coupon_id_<?php echo ($v["id"]); ?>' value="<?php echo $v['id'];?>" >
            <span class='appoint' _v='<?php echo ($v["id"]); ?>' style='color:#337ab7;cursor:pointer;' > 指定发放</span>&nbsp;&nbsp;&nbsp;
            <?php  } ?>
            <a target="_blank" href='/home/coupon/detail?coupon_id=<?php echo ($v["id"]); ?>'>查看详情</a>
        </div>
    </div>
    <?php if(($k+1)%3==0 || $coupon[$k+1]['id']<1){ ?>
</div>
<?php } ?>
<?php } ?>
</div>

<div class="clear"></div>
<script type='text/javascript'>
    $(document).ready(function(){
    var number = 12;
    function loaddata()
    {
        if(number ==-1){
            return;
        }
        totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());

        if ($(document).height() <= totalheight)
        {
            var type = $("#type").val();
            var status = $("#status").val();
            var store_id = $("#store").val();
            $.ajax({ url: "/home/coupon/appendIndex?store_id="+store_id+"&start="+number+"&status="+status+"&type="+type,async:true, success: function(msg){
                    if(msg == 'false'){
                        number = -1;
                        return ;
                    }
                    var html = "";
                    msg = eval('(' + msg + ')');
                    $.each(msg,function(i,v){
                        if(i%3==0){
                            html += "<div class='row'>";
                        }
                        html +="<div class='col-sm-3 col-md-4 full'>";
                        html += "<div class='thumbnail' style='margin-bottom:10px'>";
                        html += "<div style='height:12rem;overflow: hidden'>";
                        html += "<a target='_blank' href='/home/coupon/info?coupon_id=";
                        html += v.id==null?'':v.id;
                        html += "'><img class='_img' style='width:100%;height:100%' src='";
                        html += v.style==null?'':v.style;
                        html += "'/></a></div></div>";
                        html += "<div class='caption' style='overflow: hidden'> <span style='margin-left: 6px'>";
                        html += v.status==null?'':v.status;
                        var nums = v.num-v.count;
                        html += '</span><span style="margin-left: 6px">已领取：';
                        html += v.count==null?'':v.count;        
                        html += '张</span><span style="margin-left: 6px">剩余：';
                        html += nums==null?'':nums;        
                        html += "张</span></div>";
                        html += "<div style='float:right;margin-right:2rem;'><a target='_blank' href='/home/coupon/detail?coupon_id=";
                        html +=v.id==null?'':v.id;
                        html +="'>查看详情</a></div>"
                        html +="</div>";
                        if((i+1)%3==0){
                            html += "</div>";
                        }
                        number += 1;
                    });
                    $('#content').append(html);
            }});
        }
    }

    $(window).scroll(function () {
        loaddata();
    });
         $("#store").change(function(){
            var store_id = $("#store").val();
            var status = $("#status").val();
            var type = $("#type").val();
            setTimeout(window.location.href='/home/coupon?store_id='+store_id+'&status='+status+'&type='+type);
        });
        $("#status").change(function(){
            var store_id = $("#store").val();
            var status = $("#status").val();
            var type = $("#type").val();
            setTimeout(window.location.href='/home/coupon?store_id='+store_id+'&status='+status+'&type='+type);
        });
        $("#type").change(function(){
            var store_id = $("#store").val();
            var status = $("#status").val();
            var type = $("#type").val();
            setTimeout(window.location.href='/home/coupon?store_id='+store_id+'&status='+status+'&type='+type);
        });

        $('.appoint').click(function(){
            var id = $(this).attr('_v');
            var coupon_name = $('#coupon_name_'+id).val();
            $('#coupon_name_').html(coupon_name);
            $('#coupon_id_').val($('#coupon_id_'+id).val());
            $('#appoint_').show();
        });

        $('#min').click(function(){
            $('#num').val($('#num').val()-1);
        });
        $('#add').click(function(){
            $('#num').val(Number($('#num').val())+1);
        });

        $('#submit').click(function(){
            var num = $('#num').val();
            var coupon_id_ = $('#coupon_id_').val();
            var mobile = $('#mobile').val();

            $.ajax({
                url: "/home/coupon/receive?mobile=" + mobile+"&num="+num+"&coupon_id_="+coupon_id_,
                async: true,
                success: function (msg) {
                    if (msg == 'false') {
                        alert(msg);
                        return false;
                    }else if(msg == 'true'){
                        alert('发放成功！');
                        window.location.reload();
                    } 
                }
            });
        });

        $('#close').click(function(){
            $('#appoint_').hide();
        });

    });
</script> 
<div id='appoint_' style="width:100%;height:100%;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
    background-color:rgba(79, 79, 79, 0.7);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style='width:30rem;margin: 40rem auto;background-color: white;font-size:1.5rem;' >
        <div class='_line3'></div>
        <img src='/public/images/error1.png' width='20px' style='float:right;margin-top:-2.2rem;margin-right:-1rem;' id='close' >
        <div style='font-size:2rem;text-align: center;'><b>优惠劵指定发放</b></div>
        <form id='form' style="margin-left:4rem;" action="/home/coupon/receive" method="post"  >
            <div >优惠劵名称：<span id='coupon_name_'></span></div>
            <div class='_line3'></div>
            <div >顾客手机号：<input type='text' name='mobile' id='mobile' placeholder="请填写顾客手机号" style='width:15rem;' > </div>
            <div class='_line3'></div>
            <div>
                发放数量：
                <input type='hidden' name='coupon_id' id='coupon_id_' value='' >
                <input class="min" id='min' name="" type="button" value="-"  />
                <input class="text_box" name="num" id='num' type="text" oninput='number()'  value="1" style="width:35px;" />
                <input class="add" id='add' name="" type="button" value="+"  /> 
            </div>
            <div class='_line3'></div>
            <div><input id='submit'  name="" type="button" value="确定发放" style='width:85%;height:5rem;text-align: center;'  />  </div>
        </form>
        <div class='_line3'></div>
    </div>
</div>
</div>
</div>
<div class='_line'></div>
<div class="newfooter">
    ©2015-2017 All Rights Reserved ( 京ICP备15010043号 ) 
</div>
<div id='mask_layer' style="text-align: center;width:100%;height:100%;overflow:hidden;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
     background-color:rgba(255, 255, 255, 0.4);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style="padding-top: 20%"><h1><b>loading<span id="_loading"></span></b></h1></div>
</div>
</body>
<script type="text/javascript" src='/public/js/top.js'></script>
</html>